using FlowCanvas.Nodes;
using OWL.Rendering.HRP;
using UnityEngine;
using UnityEngine.Rendering;
using Yoozoo.Core.Common;

namespace Yoozoo.Gameplay.Liberty.Nodes
{
    public class SetTiltShiftBlurDOF : CallableActionNode<bool,float,float,float,float,float,Color>
    {
        public override void Invoke(bool active, float focusDistance, float focusRange, float bokehRadius, float smooth, float maskRange, Color addColor)
        {
            if (TimelineUtils.FreeRenderScene)
            {
                VolumeQualityListener volumeQualityListener = TimelineUtils.FreeRenderScene.GetComponentInChildren<VolumeQualityListener>();
                if (volumeQualityListener)
                {
                    Volume volume = volumeQualityListener.styleSettings[volumeQualityListener.styleSettings.Count - 1].Volume;

                    foreach (var component in volume.profile.components)
                    {
                        if (component is HTiltShiftBlurDOF)
                        {
                            HTiltShiftBlurDOF dof = component as HTiltShiftBlurDOF;
                            component.active = active;
                            dof.focusDistance.value = focusDistance;
                            dof.focusRange.value = focusRange;
                            dof.bokehRadius.value = bokehRadius;
                            dof.smooth.value = smooth;
                            dof.maskRange.value = maskRange;
                            dof.addColor.value = addColor;
                            break;
                        }
                    }
                }
            }
        }
    }
}